import Vue from "vue";
import VueRouter from "vue-router";
import { afterRouter, beforeRouter } from "./routerBefore";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    component: () => import("../views/Home.vue"),
    meta: {
      title: "首页"
    }
  },
  {
    path: "/company",
    name: "Company",
    component: () => import("../views/Company.vue"),
    meta: {
      title: "公司介绍"
    }
  },
  {
    path: "/news",
    name: "News",
    component: () => import("../views/News.vue"),
    meta: {
      title: "新闻介绍"
    }
  },
  {
    path: "/project",
    name: "Project",
    component: () => import("../views/Project.vue"),
    meta: {
      title: "项目介绍"
    }
  },
  {
    path: "/about",
    name: "About",
    component: () => import("../views/About.vue"),
    meta: {
      title: "关于我们"
    }
  }
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { x: 0, y: 0 };
    }
  }
});

router.beforeEach(beforeRouter);
router.afterEach(afterRouter);

export default router;
